package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import logic.CRUDUsers;

public class restorePassword extends JFrame {

	private JPanel contentPane;
	private JTextField emailField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					restorePassword frame = new restorePassword();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public restorePassword() {
		setTitle("Redefinir senha");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 443, 148);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblEmail = new JLabel("E-mail");
		lblEmail.setBounds(54, 53, 60, 15);
		contentPane.add(lblEmail);
		
		emailField = new JTextField();
		emailField.setBounds(131, 47, 135, 27);
		contentPane.add(emailField);
		emailField.setColumns(10);
		
		JButton btnNewButton = new JButton("redefinir");
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				try {
					if (CRUDUsers.retrievePassword(emailField.getText()))
						JOptionPane.showMessageDialog(null, "Usuario nao cadastrado");
					else
						JOptionPane.showMessageDialog(null, "Senha enviada para e-mail");
				} catch (Exception e2) {
					JOptionPane.showMessageDialog(null, "E-mail nao pode ser enviado por " + e2.getMessage());
				}
			}
		});
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.setBounds(283, 47, 100, 27);
		contentPane.add(btnNewButton);
	}
}
